package com.jn.news.ui;

import android.content.Intent;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.jn.news.R;
import com.jn.news.utils.Constant;
import com.jn.news.utils.SPUtils;


/**
 * 启动页
 */
public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initData();
    }

    /**
     * 闪屏页，用来判断是跳转到登录页面还是直接进入首页
     */
    private void initData(){
        //从sp中获取是否设置了自动登录
        boolean autoLogin = (boolean) SPUtils.get(this, Constant.AUTO_LOGIN, false);
        String userName = (String) SPUtils.get(this, Constant.USERNAME, "");
        String password = (String) SPUtils.get(this, Constant.PASSWORD, "");
        //如果设置了自动登录并且sp中保存了用户名和密码就挑战到首页，否则跳转到登录页面
        if(autoLogin && !userName.isEmpty() && !password.isEmpty()){
            startActivity(new Intent(this, HomeActivity.class));
            finish();
        }else{
            startActivity(new Intent(this, MainActivity.class));
            finish();
        }
    }
}